package com.vote.admin.controller;

import com.vote.common.returns.RespEntity;
import com.vote.admin.service.VoteUserIndexService;
import com.vote.admin.vo.result.UserResult;
import com.vote.admin.vo.result.VoteListResult;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
 * <p>
 * 用户投票系统主页 前端控制器
 * </p>
 *
 * @author gyg
 * @since 2021-05-18
 */
@RestController
@RequestMapping("/user-index")
@Slf4j
@Api(value = "用户投票系统主页", tags = "用户投票系统主页")
public class VoteUserIndexController {

    @Resource
    private VoteUserIndexService voteUserIndexService;

    @ApiOperation(value = "投票活动列表")
    @GetMapping("/list")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageNum", value = "当前页数", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "pageSize", value = "每页数量", required = true),
            @ApiImplicitParam(paramType = "query", dataType = "String", name = "content", value = "投票活动名称", required = false),
            @ApiImplicitParam(paramType = "query", dataType = "Integer", name = "status", value = "投票活动状态", required = false),
    })
    public RespEntity<VoteListResult> getVoteProjectList(@RequestParam(value = "pageNum", required = true) Integer pageNum,
                                                         @RequestParam(value = "pageSize", required = true) Integer pageSize,
                                                         @RequestParam(value = "content", required = false) String content,
                                                         @RequestParam(value = "status", required = false) Integer status) {
        RespEntity<VoteListResult> respEntity = voteUserIndexService.getVoteProjectList(pageNum, pageSize, content, status);
        return respEntity;
    }

    @GetMapping("/info")
    @ApiOperation(value = "用户信息")
    public RespEntity<UserResult> userInfo(HttpSession session) {
        RespEntity<UserResult> respEntity = voteUserIndexService.userInfo(session);
        return respEntity;
    }

    @DeleteMapping("/exit")
    @ApiOperation(value = "退出登录")
    public RespEntity signOut(HttpSession session) {
        RespEntity respEntity = voteUserIndexService.signOut(session);
        return respEntity;
    }

    @PostMapping("/access")
    @ApiOperation(value = "访问量数据接入")
    public RespEntity visitAccess() {
        RespEntity respEntity = voteUserIndexService.visitAccess();
        return respEntity;
    }

}
